package com.wwtech.epp.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * Created by hu on 2017/5/5.
 */

public class TimeUtil {
    /**
     * 调用此方法输入所要转换的时间戳输入例如（1402733340）输出（"2014年06月14日16时09分00秒"）
     *
     * @param time
     * @return
     */
    public static String timesTamp2Year(long time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        @SuppressWarnings("unused")
        String times = sdr.format(new Date(time));
        return times;
    }

    /**
     * 调用此方法输入所要转换的时间戳输入例如（1402733340）输出（"2014年06月14日16时09分00秒"）
     *
     * @param time
     * @return
     */
    public static String timesTamp2YearMonthDay(long time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd");
        @SuppressWarnings("unused")
        String times = sdr.format(new Date(time));
        return times;
    }

    /**
     * 获取未来7天的集合（格式为：周末 5月7日）
     */
    public static ArrayList<String> getDate() {
        // + 7*24*60*60*1000
        ArrayList<String> backList = new ArrayList<>();
        Calendar c = Calendar.getInstance();
        final long mills = c.getTimeInMillis();
        Calendar c7 = Calendar.getInstance();
        for (long i = 0; i < 30; i++) {
            ArrayList<String> dateList = new ArrayList<>();
            c7.setTimeInMillis(mills + (i* 24*60*60*1000));
//            KLog.i(timesTamp2Year(c7.getTimeInMillis()));
//            Logger.i(c7.getTimeInMillis() + "");
            String date = "周" + en2Zh(c7.get(Calendar.DAY_OF_WEEK)) + (c7.get(Calendar.MONTH) + 1) + "月" + c7.get(Calendar.DAY_OF_MONTH) + "日";
            backList.add(date);
//            if (i == 0) {
//                dateList.add("0");
//            } else {
//                dateList.add("1");
//            }
//            backList.add(dateList);
        }
        return backList;
    }

    public static String en2Zh(int day) {
        switch (day) {
            case 2:
                return "一  ";
            case 3:
                return "二  ";
            case 4:
                return "三  ";
            case 5:
                return "四  ";
            case 6:
                return "五  ";
            case 7:
                return "六  ";
            case 1:
                return "日  ";
        }
        return "";
    }

    /**
     *
     * @param flag 0表示从0点开始， 1表示从当天的小时开始
     * @return
     */
    public static ArrayList<String> get24(int flag) {
        ArrayList<String> backList = new ArrayList<>();
        if (flag != 1) {
            for (int i = 0; i <= 23; i++) {
                String time = i + ":00~" + (i + 1) + ":00";
                backList.add(time);
            }
        } else {
            for (int i = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); i <= 23; i++) {
                String time = i + ":00~" + (i + 1) + ":00";
                backList.add(time);
            }
        }
        return backList;
    }

    /**
     * 调此方法输入所要转换的时间输入例如（"2014-06-14 16:09:00"）返回时间戳
     *
     * @param time
     * @return
     */
    public static long timeStamp(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        Date date;
//        KLog.i(time);
        String times = null;
        try {
            date = sdr.parse(time);
            long l = date.getTime();
//            KLog.i(l);
            return l;
        } catch (Exception e) {
            e.printStackTrace();
            return new Long("123");
        }
    }
    /**
     * 调用此方法，返回输入的时间与当时的时间相差的分和秒
     */

//    public static String getiDefferTime(String time) {
//        long tenMinute = SpUtil.getInt(AppConfig.getInstance(), ContainValue.INTERVALTIME, 600) * 1000;
//        long defferTime = tenMinute - (Calendar.getInstance().getTimeInMillis() - timeStamp(time));
//        long minute = defferTime / 1000 / 60;
//        long second = defferTime / 1000 % 60;
//        return minute + "分" + second + "秒";
//    }
}
